﻿/* ######################################## *\
 * ### Copyright (C) 2009 AJ Ravindiran ### *
 * ### HTTP://THEAJ.NET/ <AJ@THEAJ.NET> ### *
\* ######################################## */
using System;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Text;

using AJRavindiran.Jolt.Utilities;
using AJRavindiran.Jolt.RuneScape.Network;
using AJRavindiran.Jolt.RuneScape.Network.Codecs;
using AJRavindiran.Jolt.RuneScape.Characters.Information;

namespace AJRavindiran.Jolt.RuneScape.Characters
{
    /// <summary>
    /// Represents a connected a connected player's character.
    /// </summary>
    public class Character
    {
        #region Fields
        private CodecFactory mCodecFactory;
        private PlayerSocket mPlayerSocket;
        private Details mDetails;

        #region Login Fields
        private double mLoginTimeout = TimeUtilities.GetCurrentMilliseconds();
        private sbyte mLoginStage = 0;
        #endregion
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets Login time out value.
        /// </summary>
        public double LoginTimeout
        {
            get { return mLoginTimeout; }
            set { mLoginTimeout = value; }
        }

        /// <summary>
        /// Gets or sets the player's login stage.
        /// </summary>
        public sbyte LoginStage
        {
            get { return mLoginStage; }
            set { mLoginStage = value; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Constructs a new Character for a player.
        /// </summary>
        /// <param name="playerSocket">The player's socket.</param>
        /// <param name="connectionID">The palyer's connectionID.</param>
        public Character(Socket playerSocket, int connectionID)
        {
            // Create a new player socket class for this character.
            this.mPlayerSocket = new PlayerSocket(this, playerSocket);

            // Create a set of details for this character.
            this.mDetails = new Details();
            this.mDetails.ConnectionID = connectionID;

            // Create a new codec factory class for this character.
            this.mCodecFactory = new CodecFactory();
        }
        #endregion

        #region Methods
        /// <summary>
        /// Accessor for Character.Information.Details class.
        /// </summary>
        public Details GetDetails()
        {
            return this.mDetails;
        }

        /// <summary>
        /// Accessor for Network.Codec.CodecFactory class.
        /// </summary>
        public CodecFactory GetCodecFactory()
        {
            return this.mCodecFactory;
        }

        /// <summary>
        /// Access for Network.PlayerSocket class.
        /// </summary>
        public PlayerSocket GetPlayerSocket()
        {
            return this.mPlayerSocket;
        }
        #endregion
    }
}
